package cn.ekgc.hbase;

import org.apache.hadoop.conf.Configuration;
import org.apache.hadoop.hbase.HBaseConfiguration;
import org.apache.hadoop.hbase.HColumnDescriptor;
import org.apache.hadoop.hbase.HTableDescriptor;
import org.apache.hadoop.hbase.TableName;
import org.apache.hadoop.hbase.client.Admin;
import org.apache.hadoop.hbase.client.Connection;
import org.apache.hadoop.hbase.client.ConnectionFactory;

public class CreateTableDemo {
    public static void main(String[] args) throws Exception {
        Configuration config = HBaseConfiguration.create(); //获取链接信息
        //创建表
        //创建链接
        try (Connection connection = ConnectionFactory.createConnection(config)) {
            Admin admin = connection.getAdmin();
            HTableDescriptor tableDescriptor = new HTableDescriptor(TableName.valueOf("gamer"));
            HColumnDescriptor cf1 = new HColumnDescriptor("personalinfo");
            HColumnDescriptor cf2 = new HColumnDescriptor("recordinfo");
            HColumnDescriptor cf3 = new HColumnDescriptor("assetsinfo");
            tableDescriptor.addFamily(cf1);
            tableDescriptor.addFamily(cf2);
            tableDescriptor.addFamily(cf3);
            System.out.print("Creating table. ");
            //do create
            admin.createTable(tableDescriptor);

            System.out.println(" Done.");

        }


    }
}
